<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>商品管理 - 后台</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
            background-color: #f8f9fa;
        }
        .admin-wrapper {
            display: flex;
        }
        .sidebar {
            flex: 0 0 220px;
            min-height: 100vh;
            background-color: #343a40;
            padding-top: 20px;
            color: white;
        }
        .sidebar .nav-link {
            color: rgba(255, 255, 255, 0.75);
            padding: 10px 15px;
            transition: background-color 0.2s;
        }
        .sidebar .nav-link:hover {
            background-color: #495057;
            color: white;
        }
        .sidebar .nav-link.active {
            background-color: #007bff;
            color: white;
        }
        .main-content {
            flex-grow: 1;
            padding: 30px;
            background-color: #fff;
            margin: 20px;
            border-radius: 8px;
            box-shadow: 0 4px 8px rgba(0,0,0,0.05);
        }
        h1 {
            color: #333;
            margin-bottom: 25px;
            border-bottom: 2px solid #007bff;
            padding-bottom: 10px;
        }
        .table-img {
            max-width: 80px;
            max-height: 80px;
            object-fit: cover;
            border-radius: 4px;
        }
        .action-buttons .btn {
            margin-right: 5px;
        }
    </style>
</head>
<body>
    <div class="admin-wrapper">
        <nav class="sidebar navbar-dark bg-dark">
            <div class="container-fluid">
                <a class="navbar-brand text-center d-block mb-4" href="{:Url('admin/index/index')}">后台管理</a>
                <ul class="nav flex-column">
                    <li class="nav-item">
                        <a class="nav-link" href="{:Url('admin/index/index')}">
                            <i class="bi bi-house-door-fill me-2"></i> 仪表盘
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link active" href="{:Url('admin/index/productList')}">
                            <i class="bi bi-box-seam me-2"></i> 商品管理
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{:Url('admin/index/userList')}">
                            <i class="bi bi-people-fill me-2"></i> 用户管理
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{:Url('admin/index/orderList')}">
                            <i class="bi bi-receipt me-2"></i> 订单管理
                        </a>
                    </li>
                     <li class="nav-item">
                        <a class="nav-link" href="{:Url('admin/index/changepassword')}">
                            <i class="bi bi-key-fill me-2"></i> 修改密码
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{:Url('index/index/logout')}">
                            <i class="bi bi-box-arrow-right me-2"></i> 退出登录
                        </a>
                    </li>
                </ul>
            </div>
        </nav>

        <div class="main-content">
            <h1 class="mb-4">商品管理</h1>
            <a href="{:Url('admin/index/addProduct')}" class="btn btn-success mb-3">
                <i class="bi bi-plus-circle me-2"></i>新增商品
            </a>

            <div class="table-responsive">
                <table class="table table-striped table-hover align-middle">
                    <thead class="table-dark">
                        <tr>
                            <th>ID</th>
                            <th>商品名</th>
                            <th>价格</th>
                            <th>简介</th>
                            <th>图片</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {foreach name="products" item="product"}
                        <tr>
                            <td>{$product.pId}</td>
                            <td>{$product.pName}</td>
                            <td>¥ {$product.pPrice}</td>
                            <td>{$product.pDescr|mb_substr=0, 50}</td>
                            <td>
                                <img src="/tp/public/static/upload/{$product.pImg}" alt="{$product.pName}" class="table-img">
                            </td>
                            <td class="action-buttons">
                                <a href="{:Url('admin/index/editProduct', ['pId' => $product.pId])}" class="btn btn-sm btn-primary">
                                    <i class="bi bi-pencil-square"></i> 编辑
                                </a>
                                <a href="{:Url('admin/index/deleteProduct', ['pId' => $product.pId])}" class="btn btn-sm btn-danger" onclick="return confirm('确定要删除这个商品吗？');">
                                    <i class="bi bi-trash"></i> 删除
                                </a>
                            </td>
                        </tr>
                        {/foreach}
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
</body>
</html>